UserView = Ext.extend(Ext.Panel, {
	constructor : function(a) {
		Ext.applyIf(this, a);
		this.initUIComponents();
		UserView.superclass.constructor.call(this, {
			id : "UserView",
			title : "会员管理",
			iconCls : "menu-appuser",
			autoScroll : true
		});
	},
	initUIComponents : function() {
		this.initSearchPanel();
		this.initGridPanel();
		this.items = [ this.searchPanel, this.gridPanel ];
	},
	onSearch : function(c) {
		var a = Ext.getCmp("UserSearchForm");
		var b = Ext.getCmp("UserGrid");
		if (a.getForm().isValid()) {
			a.getForm().submit( {
				waitMsg : "正在提交查询",
				url : __ctxPath + "/system/listUser.do",
				success : function(e, f) {
					var d = Ext.util.JSON.decode(f.response.responseText);
					b.getStore().loadData(d);
				}
			});
		}
	}
});
UserView.prototype.initSearchPanel = function() {
	this.searchPanel = new Ext.FormPanel( {
		height : 35,
		frame : false,
		border : false,
		id : "UserSearchForm",
		layout : "hbox",
		layoutConfig : {
			padding : "5",
			align : "middle"
		},
		defaults : {
			xtype : "label",
			border : false,
			margins : {
				top : 0,
				right : 4,
				bottom : 4,
				left : 4
			}
		},
		items : [ {
			text : "用户账号"
		}, {
			xtype : "textfield",
			name : "Q_name_S_LK"
		}, {
			xtype : "button",
			text : "查询",
			iconCls : "search",
			scope : this,
			handler : this.onSearch.createCallback(this)
		} ]
	});
};

UserView.prototype.initGridPanel = function() {
	
	var b = new Ext.data.Store( {
		proxy : new Ext.data.HttpProxy( {
			url : __ctxPath + "/system/listUser.do"
		}),
		reader : new Ext.data.JsonReader( {
			root : "result",
			totalProperty : "totalCounts",
			fields : [ "id", "name", "sex", "registerTime", "lastLoginTime", "address", "email","status"]
		}),
		remoteSort : true
	});
	b.load( {
		params : {
			start : 0,
			limit : 25
		}
	});
	var e = new Ext.grid.CheckboxSelectionModel();
	var a = new Ext.grid.ColumnModel(
			{
				columns : [
						e,
						new Ext.grid.RowNumberer(),
						{
							header : "id",
							dataIndex : "id",
							hidden : true
						},
						{
							header : "状态",
							dataIndex : "status",
							width : 30,
							renderer : function(f) {
								var g = "";
								if (f == "1") {
									g += '<img title="激活" src="' + __ctxPath + '/images/flag/customer/effective.png"/>';
								} else {
									g += '<img title="禁用" src="' + __ctxPath + '/images/flag/customer/invalid.png"/>';
								}
								return g;
							}
						},
						{
							header : "账号",
							dataIndex : "name",
							width : 60
						},
						{
							header : "性别",
							dataIndex : "sex",
							width : 60
						},
						{
							header : "邮箱",
							dataIndex : "email",
							width : 120
						},
						{
							header : "注册时间",
							dataIndex : "registerTime",
							width : 100
						},
						{
							header : "最后一次登录时间",
							dataIndex : "lastLoginTime",
							width : 100
						},
						{
							header : "地址",
							dataIndex : "address",
							width : 100
						},
						{
							header : "管理",
							dataIndex : "id",
							sortable : false,
							width : 60,
							renderer : function(j, i, g, m, h) {
								var l = g.data.id;
								var f = g.data.name;
								var k = "";
								if (isGranted("_UserEdit")) {
									k += '&nbsp;<button title="编辑" value=" " class="btn-edit" onclick="UserView.edit(\'' + l + '\')"></button>';
								}
								return k;
							}
						} ]
			});
	this.gridPanel = new Ext.grid.GridPanel( {
		id : "UserGrid",
		store : b,
		autoHeight : true,
		shim : true,
		trackMouseOver : true,
		disableSelection : false,
		loadMask : true,
		cm : a,
		sm : e,
		viewConfig : {
			forceFit : true,
			enableRowBody : false,
			showPreview : false
		},
		bbar : new Ext.PagingToolbar( {
			pageSize : 25,
			store : b,
			displayInfo : true,
			displayMsg : "当前显示从{0}至{1}， 共{2}条记录",
			emptyMsg : "当前没有记录"
		})
	});
	this.gridPanel.addListener("rowdblclick", d);
	var c = this.gridPanel;
	function d(g, f, h) {
		g.getSelectionModel().each(function(j) {
			var i = j.data.id;
			if (isGranted("_UserEdit")) {
				UserView.edit(i);
			}
		});
	}
};

UserView.edit = function(a) {
	new UserForm( {
		id : a
	}).show();
};